package com.guyu.common.core.enums;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 是否删除
 */
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum DeletedEnum {

    NORMAL(0L, "未删除"),
    DELETED(1L, "已删除"),//非0以外都是删除
    ;

    private final Long code;
    private final String desc;

    /**
     * code!=1都认为是false
     */
    public static boolean isDeleted(Long code) {
        return !Objects.equals(DeletedEnum.NORMAL.getCode(), code);
    }

    public static DeletedEnum getCode(Long code) {
        return Objects.equals(DeletedEnum.NORMAL.getCode(), code) ? DeletedEnum.NORMAL : DeletedEnum.DELETED;
    }

    public static DeletedEnum getEnum(boolean value) {
        return value ? DeletedEnum.DELETED : DeletedEnum.NORMAL;
    }

    public static Long getCode(boolean value) {
        return value ? DeletedEnum.DELETED.getCode() : DeletedEnum.NORMAL.getCode();
    }

}
